package com.vehicle.mq.handler;

import com.vehicle.mq.constant.EventCommandEnum;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by yantingbin on 2017/11/30.
 */
public class MessageDispatcher {
    private final Map<EventCommandEnum, MessageHandler> HANDLER_MAP = new ConcurrentHashMap<>();

    private MessageDispatcher() {
        HANDLER_MAP.put(EventCommandEnum.SMS, new SmsHandler());
        HANDLER_MAP.put(EventCommandEnum.MAIL, new MailHandler());
    }

    public static MessageDispatcher getInstance() {
        return Single.MESSAGE_DISPATCH;
    }

    private static class Single {
        private static final MessageDispatcher MESSAGE_DISPATCH = new MessageDispatcher();
    }

    public MessageHandler getMessageHandler(EventCommandEnum ee) {
        return  HANDLER_MAP.get(ee);
    }
}
